<template>
  <view :style="colorStyle" class="wrap">
    <template v-if="tableData.length">
      <view class="header">
        <view class="logo_name flex_s">
          <text v-if="enterprise_name_show">{{ enterprise_name }}</text>
        </view>
        <!-- <view class="extra_box flex_s">
          <view
            class="extra_item pad1020"
            v-if="is_money_remind && isWeixin()"
            @click="tipHandler"
          >
            到价提醒
          </view>
          <view class="share_box flex_c" @click="shareMasker = true">
            <text class="iconfont icon-fenxiang"></text>
          </view>
        </view> -->

        <view class="swiper_box" :class="{ minHeight: !bannerList.length }">
          <swiper
            :style="'height:' + imageH + 'px;'"
            class="swiper"
            circular
            :autoplay="true"
          >
            <swiper-item
              v-for="(item, index) in bannerList"
              :key="index"
              @click="bannerClick(item)"
            >
              <view class="masker"></view>
              <view class="swiper_item">
                <image :src="item.images" mode="widthFix" />
              </view>
            </swiper-item>
          </swiper>
        </view>
        <view class="menu_box flex_se">
          <view class="open_right">
            <view class="top_time_box">
              <view>{{ currentTimeDate }}</view>
              <view>{{ currentTimeHour }}</view>
            </view>

            <view class="top_status_box flex_s">
              <view class="status_box pad10" v-if="is_business_status"
                >开盘</view
              >
              <view class="status_box close_status pad10" v-else>闭盘</view>
              <view class="status_text pad10">实时金价</view>
            </view>
          </view>
        </view>
      </view>
      <view class="notice_box" v-if="noticeList.length">
        <next-notice-bar :row="1" :speed="30" :list="noticeList">
          <template #default="{ row }">
            <view class="notice-bar-item">
              <rich-text :nodes="row"></rich-text>
            </view>
          </template>
        </next-notice-bar>
      </view>
      <view class="container">
        <template v-for="(item, index) in tableData" :key="index">
          <view class="tabale_item" v-if="item.list.length">
            <view class="tabale_title" v-if="+item.is_show">
              {{ item.title }}
            </view>
            <view class="table_box" :class="{ hidde_title: !+item.is_show }">
              <uni-table ref="table" stripe emptyText="暂无更多数据">
                <uni-tr v-if="index == 0">
                  <uni-th style="width: 25%" align="center">
                    <view class="table_th"> 商品 </view>
                  </uni-th>
                  <uni-th style="width: 25%" align="center">
                    <view class="table_th"> 回购 </view>
                  </uni-th>
                  <uni-th style="width: 25%" align="center">
                    <view class="table_th"> 销售 </view>
                  </uni-th>
                  <uni-th
                    style="width: 25%"
                    align="center"
                    v-if="high_low_show"
                  >
                    <view class="table_th"> 高/低 </view>
                  </uni-th>
                </uni-tr>
                <template v-else>
                  <uni-tr v-show="+item.is_show">
                    <uni-th style="width: 25%" align="center">
                      <view class="table_th"> 商品 </view>
                    </uni-th>
                    <uni-th style="width: 25%" align="center">
                      <view class="table_th"> 回购 </view>
                    </uni-th>
                    <uni-th style="width: 25%" align="center">
                      <view class="table_th"> 销售 </view>
                    </uni-th>
                    <uni-th
                      style="width: 25%"
                      align="center"
                      v-if="high_low_show"
                    >
                      <view class="table_th"> 高/低 </view>
                    </uni-th>
                  </uni-tr>
                </template>

                <uni-tr
                  v-for="(_item, _index) in item.list"
                  :key="_index"
                  :class="[
                    { th1: _item.row_jwo_class == 1 },
                    { th2: _item.row_jwo_class == 0 },
                  ]"
                >
                  <uni-td align="center" style="width: 25%">
                    <view class="table_td name_td">{{ _item.code_name }}</view>
                  </uni-td>
                  <uni-td align="center" style="width: 25%">
                    <view
                      class="table_td"
                      :class="[
                        { colorRed: _item.colour_bidprice == 1 },
                        { colorGreen: _item.colour_bidprice == 2 },
                        {
                          colorGreenLight:
                            Cache.get('themeValue') &&
                            Cache.get('themeValue') == 'dark',
                        },
                      ]"
                    >
                      {{ _item.bidprice || "--" }}
                    </view>
                  </uni-td>
                  <uni-td align="center" style="width: 25%">
                    <view
                      class="table_td"
                      :class="[
                        { colorRed: _item.colour_askprice == 1 },
                        { colorGreen: _item.colour_askprice == 2 },
                        {
                          colorGreenLight:
                            Cache.get('themeValue') &&
                            Cache.get('themeValue') == 'dark',
                        },
                      ]"
                    >
                      {{ _item.askprice || "--" }}
                    </view>
                  </uni-td>
                  <uni-td align="center" v-if="high_low_show">
                    <view class="table_td font_samll">
                      <view class="colorRed">
                        {{ _item.high || "--" }}
                      </view>
                      <view
                        class="colorGreen"
                        :class="{
                          colorGreenLight:
                            Cache.get('themeValue') &&
                            Cache.get('themeValue') == 'dark',
                        }"
                      >
                        {{ _item.low || "--" }}
                      </view>
                    </view>
                  </uni-td>
                </uni-tr>
              </uni-table>
            </view>
          </view>
        </template>
      </view>
      <view class="footer">
        <view class="text_item">
          <text>声明：</text><text class="red_class">以上行情仅供参考！</text>
        </view>
        <view class="text_item red_class" v-if="declare_content">
          {{ declare_content }}
        </view>
        <template v-if="contacts.length">
          <view
            class="text_item"
            v-for="(item, index) in contacts"
            :key="index"
            @click="makePhone(item.phone)"
          >
            <text class="iconfont icon-dianhua"></text>
            <text>{{ item.name }} {{ item.phone }}</text>
          </view>
        </template>

        <view class="text_item" v-if="enterprise_address">
          <text class="iconfont icon-dizhi"></text>
          <text>{{ enterprise_address }}</text>
        </view>
      </view>
      <view class="free_tip" @click="goMpHanlder">
        终身免费报价盘（申请）
      </view>
    </template>
    <!-- 联系方式弹窗 -->
    <up-popup
      :show="show"
      @close="close"
      round="20"
      :safeAreaInsetBottom="false"
    >
      <view class="pop_box1">
        <text class="iconfont icon-guanbi1" @click="close"></text>
        <view class="pop_title">联系电话</view>
        <view class="info_box">
          <view class="phone_box" v-if="contacts.length">
            <a
              class="phone_item flex_s"
              v-for="(item, index) in contacts"
              :key="index"
              @click="makePhone(item.phone)"
            >
              <image src="@/static/image/phone.png" mode="scaleToFill" />
              <view class="phone_info">
                <view class="text1">联系热线</view>
                <view class="text2">{{ item.name + " " + item.phone }}</view>
              </view>
            </a>
          </view>
        </view>
      </view>
    </up-popup>
    <!-- 联系地址弹窗 -->
    <up-popup
      :show="show2"
      @close="close2"
      mode="center"
      round="20"
      :safeAreaInsetBottom="false"
    >
      <view class="pop_box2">
        <view class="pop_title">公司地址</view>
        <view class="info_box">
          <view class="address_info">{{ enterprise_address }}</view>
        </view>
        <view class="theme_btn btn_box" @click="copyUrlHandler">复制</view>
      </view>
    </up-popup>
    <!-- 到价提醒 -->
    <up-popup
      :show="show3"
      @close="close3"
      round="20"
      :safeAreaInsetBottom="false"
    >
      <view class="pop_box">
        <view class="pop_title">到价提醒</view>
        <view class="pop_body" v-if="remindList.length">
          <view class="set_item flex_sb set_item1">
            <view class="input_item">商品</view>
            <view class="input_item">方向</view>
            <view class="input_item">价格</view>
          </view>
          <view
            class="set_item flex_sb"
            v-for="(item, index) in remindList"
            :key="index"
          >
            <view
              class="input_item"
              :class="{ black: item.title }"
              @click="openPik1(index)"
            >
              {{ item.title || "请选择" }}
            </view>
            <view
              class="input_item"
              :class="{ black: item.is_type == 1 || item.is_type == 2 }"
              @click="openPik2(index)"
            >
              <text v-if="item.is_type == 1"> 销售 </text>
              <text v-else-if="item.is_type == 2"> 回购 </text>
              <text v-else> 请选择 </text>
            </view>
            <view class="input_item">
              <input
                type="digit"
                placeholder="请输入价格"
                placeholder-class="input_placeholder"
                v-model="item.price"
              />
            </view>
            <view
              class="iconfont icon-guanbi1"
              @click="delTipHandler(index)"
            ></view>
          </view>
        </view>
        <view class="pop_footer btn_box flex_sb">
          <view class="pop_btn_item">
            <wx-open-subscribe
              template="9SYqoZRxl_Z1Qw74WzNPux05CB6TvLdqXk05hWKUHZQ"
              id="subscribe-btn"
              @error="onSubscribeError"
              @success="onSubscribeSuccess"
            >
              <component :is="'script'" type="text/wxtag-template">
                <component :is="'style'">
                  .btn{ width: 100%;;display: flex;
                  justify-content:center;align-content: center}
                  .subscribe-btn{color: #000;font-weight:700;font-size:14px;
                  text-align: center;}
                </component>
              </component>
              <component :is="'script'" type="text/wxtag-template">
                <div class="btn">
                  <button class="subscribe-btn">新增提醒</button>
                </div>
              </component>
            </wx-open-subscribe>
          </view>
          <view class="pop_btn_item btn_item2" @click="tipSaveHandler">
            保存设置
          </view>
        </view>
      </view>
    </up-popup>

    <!-- 品类列表弹窗 -->
    <up-picker
      :show="picker1"
      :columns="policyList"
      keyName="title"
      @cancel="closePik1"
      @confirm="pik1Confirm"
    ></up-picker>
    <!-- 选择方向列表弹窗 -->
    <up-picker
      :show="picker2"
      :columns="columns"
      keyName="title"
      @cancel="closePik2"
      @confirm="pik2Confirm"
    ></up-picker>

    <!-- 分享遮罩层 -->
    <view
      class="share_makser"
      @touchmove.stop.prevent=""
      v-if="shareMasker"
      @click="shareMasker = false"
    >
      <view class="img_box">
        <image src="@/static/image/share_img.png" mode="scaleToFill" />
      </view>
    </view>

    <!-- 关注弹窗start------- -->
    <view class="followCode" v-if="openFollowCode">
      <view class="pictrue">
        <view class="img_box">
          <image :src="wechat_qrcode" mode="aspectFill" />
        </view>

        <view class="follow_text"> 长按图片即可关注 </view>
      </view>
      <view class="mask" @click="closeFollowCode"></view>
    </view>
    <!-- 关注弹窗end------- -->
    <view class="uni-p-b-98"></view>
    <pageFooter
      :is_gold_basis="is_gold_basis"
      :is_money_remind="is_money_remind"
      :isShowAllMenu="isShowAllMenu"
      :shareData="shareData"
      v-if="tableData.length"
    ></pageFooter>
  </view>
</template>

<script setup lang="ts">
import pageFooter from "@/components/pageFooter/index.vue";
import { watch, watchEffect } from "vue";
import { onLoad, onUnload, onHide, onShow } from "@dcloudio/uni-app";
import { useTheme } from "@/composables/useTheme";
import {
  marketGet,
  getPolicyList,
  getReminderList,
  getSave,
  remove,
} from "@/api/home";
import { JumpPath, timeFormat, Tips, isWeixin } from "@/utils";
import { checkLogin, toLogin } from "@/libs/login";
import Cache from "@/utils/cache";
import { USER_INFO, LOGIN_STATUS } from "@/config/cache";
let websocketUtil = inject("websocketUtil");
import themeList from "@/utils/theme";
import wx from "weixin-js-sdk";
import { getWechatShare } from "@/api/public";
import { getOpenidByCode, getCurlOauth, getWechatFollow } from "@/api/user";
import { useTokenStore } from "@/store/index";
import hideWechatMenu from "@/composables/hideWechatMenu";
const { colorStyle } = useTheme();
let timer = ref(null);
let currentTime = ref("");
let currentTimeDate = ref("");
let currentTimeHour = ref("");
let contacts = ref([]);
let enterprise_address = ref("");
let myBusinessId = ref(0);
let wechat_share = reactive({});
let home_url = ref("");
let isShowAllMenu = ref(false);
let shareData = ref({
  business_id: "",
  urltype: "",
});

onLoad(async (option) => {
  uni.showLoading();
  // 分享进来的存储，底部菜单区分
  if (option.business_id) {
    shareData.value.business_id = option.business_id;
    shareData.value.urltype = option.urltype;

    Cache.set("urltype", option.urltype);
    Cache.set("business_id", option.business_id);
    isShowAllMenu.value = false;
  }
});
let userInfo = reactive({});
// 公告start-----
let noticeList = ref([]);
// 公告end-----
onShow(async () => {
  let { data } = await getWechatShare(); //获取域名用于分享和授权链接设置所以写在最前面
  wechat_share = data.wechat_share;
  home_url.value = data.home_url;
  if (isWeixin()) {
    // 微信浏览器环境需授权登录，token用于首页到价提醒功能操作
    setTokenHandler();
  }
  if (Cache.get("business_id")) {
    isShowAllMenu.value = false;
  } else {
    isShowAllMenu.value = true;
  }
  // 监听行情更新事件
  uni.$on("marketUpdate", (data) => {
    uni.hideLoading();
    if (data.data.busione && data.data.busione.id) {
      myBusinessId.value = data.data.busione.id;
    }
    // console.log(data, "接收的数据");

    setData(data);
  });
  if (Cache.get(USER_INFO)) {
    userInfo = JSON.parse(Cache.get(USER_INFO));
  }

  getDataHandler();
});

let shareMasker = ref(false);
// 获取公众号授权链接并跳转
async function getCurlOauthHandler() {
  let redirect_url = `${home_url.value}/pages/tabbar/home`;
  if (Cache.get("business_id")) {
    redirect_url += `?business_id=${Cache.get("business_id")}`;
  }
  if (Cache.get("urltype")) {
    redirect_url += `&urltype=${Cache.get("urltype")}`;
  }
  let params = { mode: 0, source: redirect_url };
  let res = await getCurlOauth(params);
  let { auth_url } = res.data;
  window.location = auth_url;
}

async function setTokenHandler() {
  const token = uni.getStorageSync(LOGIN_STATUS);
  var url = window.location.href;
  var theRequest = new Object();
  if (url.indexOf("?") != -1) {
    var str = url.substr(url.indexOf("?") + 1);
    var strs = str.split("&");
    for (var i = 0; i < strs.length; i++) {
      theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
    }
  }
  if (theRequest.code) {
    // 存在code时，调用接口获取token
    // 使用code和state调用接口获取普通用户的token
    let res = await getOpenidByCode({
      code: theRequest.code,
      state: theRequest.state,
    });
    let { data, code, info } = res;
    let token = data.token.token;
    const tokenStore = useTokenStore();
    await tokenStore.setToken(token);
    if (code != 1) {
      return Tips({
        title: info,
      });
    }

    return;
  }
  if (!token) {
    //没有授权token 时，获取跳转链接让用户授权公众号登录获取code
    getCurlOauthHandler();
    return;
  }
}
onHide(() => {
  closeFollowCode();
  clearInterval(timer.value);
  uni.$off("marketUpdate");
});
onUnload(() => {
  closeFollowCode();
  clearInterval(timer.value);
  uni.$off("marketUpdate");
});

let remindList = ref([]);
// 我的提醒列表
async function getRemindListListHanlder(id) {
  let { data } = await getReminderList({ business_id: id });
  remindList.value = data.list;
}
// 添加提醒
async function remindSaveHandler(id) {
  const params = {
    business_id: userInfo.id, //企业资料的企业ID
    date_json: JSON.stringify(remindList.value),
  };

  let { data, info } = await getSave(params);
  Tips({
    title: info,
  });
  getRemindListListHanlder(userInfo.id);
  close3();
}
// 到价提醒
async function addTipHandler() {
  remindList.value.push({
    title: "",
    is_type: "",
    price: "",
  });
}
function tipSaveHandler() {
  if (!remindList.value.length) return Tips({ title: "请添加提醒" });
  const emptyItem = remindList.value.find(
    (item) => !item.policy_id || !item.is_type || !item.price
  );
  if (emptyItem) {
    Tips({ title: "请完善信息" });
    return;
  }
  remindSaveHandler();
}
function delTipHandler(index) {
  if (remindList.value[index].id) {
    // 从数据中删除
    uni.showModal({
      content: "是否确认删除",
      success: (res) => {
        if (res.confirm) {
          removeTipHandler(remindList.value[index].id);
        }
      },
    });
  } else {
    //删除自定义添加的订阅项
    remindList.value.splice(index, 1);
  }
}
async function removeTipHandler(id) {
  const params = { id, business_id: userInfo.id };
  const { info } = await remove(params);
  Tips({
    title: info,
  });
  getRemindListListHanlder(userInfo.id);
}
let remindCurrent = ref(0); //选择的第几个订阅索引
const picker1 = ref(false);
function openPik1(index) {
  remindCurrent.value = index;
  picker1.value = true;
}
function closePik1() {
  picker1.value = false;
}
// 品类确认
function pik1Confirm(e) {
  const data = e.value[0];
  remindList.value[remindCurrent.value].policy_id = data.id;
  remindList.value[remindCurrent.value].title = data.title;
  closePik1();
}

const picker2 = ref(false);
const columns = ref([
  [
    { id: 1, title: "销售" },
    { id: 2, title: "回购" },
  ],
]);
function openPik2(index) {
  remindCurrent.value = index;
  picker2.value = true;
}
function closePik2() {
  picker2.value = false;
}
// 品类确认
function pik2Confirm(e) {
  const data = e.value[0];
  remindList.value[remindCurrent.value].is_type = data.id;
  closePik2();
}
let policyList = ref([]);
async function getPolicyListHanlder(id) {
  let { data } = await getPolicyList({ business_id: id });
  policyList.value = [data.list];
}
let tableData = ref([]);
let bannerList = ref([]);

let wechat_qrcode = ref("");
let openFollowCode = ref(false);
function closeFollowCode() {
  openFollowCode.value = false;
}
async function tipHandler() {
  // 判断是否关注start------
  // 判断是否关注公众号
  let { data } = await getWechatFollow();

  wechat_qrcode.value = data.wechat_qrcode;
  if (data.subscribe) {
    // 关注之后才能添加提醒

    const businessId = Cache.get("business_id");
    // 获取订阅数据
    let business_id = businessId ? businessId : userInfo.id;
    await getPolicyListHanlder(business_id); //获取可订阅的分类列表
    await getRemindListListHanlder(business_id); //获取订阅列表
    if (!policyList.value.length) return Tips({ title: "暂无可订阅列表" });
    open3();
  } else {
    // 否则打开关注公众号弹窗
    openFollowCode.value = true;
  }
  // 判断是否关注end------
}
function getDataHandler() {
  getCurrentTime();
  let params = {
    business_id: shareData.value.business_id || userInfo.id,
    is_type: "wechat",
    message: JSON.stringify("金价请求"),
  };

  websocketUtil.sendMsg(params);
  clearInterval(timer.value);
  timer.value = setInterval(() => {
    getDataHandler();
  }, 1000);
}
let marketListRef = ref([]);
let hasDataIndex = ref(0);
function setTabalDataHandler() {
  for (const key in marketListRef.value) {
    tableData.value.forEach((item, index) => {
      if (item.id == key) {
        item.list = marketListRef.value[key];
      }
    });
  }
  let findIndex = tableData.value.findIndex((item) => item.list.length);
  if (findIndex > -1) hasDataIndex.value = findIndex;
}

function getCurrentTime() {
  currentTime.value = timeFormat(new Date(), "yyyy-mm-dd hh:MM:ss");
  let dateArr = currentTime.value.split(" ");
  currentTimeDate.value = dateArr[0];
  currentTimeHour.value = dateArr[1];
}

let high_low_show = ref(true);
let is_market_title = ref(true);
let is_business_status = ref(true);
let declare_content = ref("");
let logoImg = ref("");
let is_money_remind = ref(false); //到价提醒展示
let is_gold_basis = ref(false); //基差是否展示
let enterprise_name_show = ref(0); //企业名称展示
let enterprise_name = ref(""); //企业名称
let update_time = ref("");
watchEffect(() => {
  // 监听分享所需的数据并设置
  wechat_share.introduction, enterprise_name.value; //PC端必须这么写，不要删除，否则不会触发
  if (wechat_share.introduction && enterprise_name.value) {
    setShareHandler();
  }
});
function setData(res) {
  getCurrentTime();
  const { busione, marketList } = res.data;
  if (!busione) return;
  // 公告(防止重新渲染noticeList.value[0] != busione.notice_content)
  if (busione.notice_content && noticeList.value[0] != busione.notice_content) {
    noticeList.value = [busione.notice_content];
  }
  high_low_show.value = !!busione.high_low_show;
  is_market_title.value = !!busione.is_market_title;
  is_business_status.value = !!busione.is_business_status;
  bannerList.value = busione.banna;
  if (bannerList.value.length) setSwiperHeight();
  logoImg.value = busione.logo;
  declare_content = busione.declare_content;
  contacts.value = busione.contacts;
  enterprise_address.value = busione.enterprise_address;
  is_money_remind.value = !!+busione.is_money_remind;
  is_gold_basis.value = !!+busione.is_gold_basis;
  enterprise_name.value = busione.enterprise_name;
  enterprise_name_show.value = busione.enterprise_name_show;
  let theme1 = busione.theme ? busione.theme : "dark";
  let theme2 = busione.theme_colour ? busione.theme_colour : "golden";
  setThemeHandler(theme1, theme2);

  if (busione.enterprise_name) {
    uni.setNavigationBarTitle({ title: busione.enterprise_name + "金价" });
  }

  uni.hideLoading();
  const list = marketList && marketList.gold_list;
  if (list) tableData.value = list;

  update_time.value = marketList.update_time; //判断什么时候有数据
  //  marketListRef.value = marketList;
  //  setTabalDataHandler();
}
// 设置主题样式
function setThemeHandler(themeValue, subThemeValue = "golden") {
  // 合并默认主题
  const mergedTheme =
    themeList["theme"][themeValue] + themeList["sub_theme"][subThemeValue];
  uni.setStorageSync("viewColor", mergedTheme);
  uni.setStorageSync("themeValue", themeValue);
  // 更新响应式变量以触发页面样式更新
  colorStyle.value = mergedTheme;
}
function setSwiperHeight() {
  uni.getImageInfo({
    src: bannerList.value.length && bannerList.value[0].images,
    success: function (res) {
      imageH.value = res.height;
    },
  });
}

let menuList = ref([
  {
    name: "联系电话",
    icon: "dianhua",
    path: "",
  },
  {
    name: "门店地址",
    icon: "dizhi",
    path: "",
  },
  {
    name: "到价提醒",
    icon: "xiaoxi",
    path: "",
  },
  {
    name: "分享海报",
    icon: "image",
    path: "",
  },
]);
let imageH = ref(0);
watch(
  () => imageH,
  (nVal, oVal) => {
    imageH.value = nVal;
  }
);
function bannerClick(item) {
  if (item.curl_http) {
    uni.navigateTo({
      url: item.curl_http,
      fail: () => {
        window.location.href = item.curl_http;
      },
    });
  }
}

// 创建响应式数据
const show = ref(false);

// 定义方法
function open() {
  // 打开逻辑，比如设置 show 为 true
  show.value = true;
}

function close() {
  // 关闭逻辑，设置 show 为 false
  show.value = false;
}
// 创建响应式数据
const show2 = ref(false);

// 定义方法
function open2() {
  // 打开逻辑，比如设置 show 为 true
  show2.value = true;
}

function close2() {
  // 关闭逻辑，设置 show 为 false
  show2.value = false;
}
// 创建响应式数据（到价提醒）
const show3 = ref(false);

// 定义方法
function open3() {
  // 打开逻辑，比如设置 show 为 true
  show3.value = true;
}

function close3() {
  // 关闭逻辑，设置 show 为 false
  show3.value = false;
}

function copyUrlHandler() {
  uni.setClipboardData({
    data: enterprise_address.value,
    success: function () {
      close2();
      uni.showToast({
        title: "复制成功",
        icon: "success",
        duration: 2000,
      });
    },
  });
}
function menuClick(item) {
  switch (item.name) {
    case "联系电话":
      if (!contacts.value.length) return Tips({ title: "暂无联系方式" });
      open();
      break;
    case "门店地址":
      if (!enterprise_address.value) return Tips({ title: "暂无门店地址" });
      open();
      break;

    default:
      break;
  }
}
function makePhone(phone) {
  uni.makePhoneCall({
    phoneNumber: phone, //仅为示例
    fail: (err) => {
      console.log(err, "----");
    },
  });
}
function isWechatDesktopHanlder() {
  const userAgent = navigator.userAgent.toLowerCase();
  return userAgent.includes("windowswechat");
}
function setShareHandler() {
  wx.ready(async () => {
    wx.showAllNonBaseMenuItem();
    wx.hideMenuItems({
      menuList: ["menuItem:copyUrl"], // 屏蔽复制链接
    });

    try {
      let link = `${home_url.value}/pages/tabbar/home?business_id=${
        shareData.value.business_id || myBusinessId.value
      }&urltype=share`;
      let imgUrl = wechat_share.image;
      let title = "";

      if (wechat_share.is_type_img == 1) {
        // 使用系统图片
        // imgUrl = wechat_share.image;
        title = wechat_share.title;
      } else {
        // imgUrl = logoImg.value;
        title = enterprise_name.value + "金价";
      }

      // 分享个人
      wx.updateAppMessageShareData({
        title: title, // 分享标题
        desc: wechat_share.introduction, // 分享描述
        link: link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
        imgUrl: imgUrl, // 分享图标
        success: function () {},
        fail: function (res) {
          // if (isWechatDesktopHanlder()) {
          //   alert(JSON.stringify(res));
          // }
          // 刷新当前页面
          location.reload();
          console.log(res);
        },
      });
      // 分享朋友圈
      wx.updateTimelineShareData({
        title: title || "", // 分享标题
        link: link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
        imgUrl: imgUrl, // 分享图标
      });
      // wx.error(function (res) {
      //   alert(res.errMsg);
      // });
    } catch (error) {
      console.log("隐藏微信菜单失败:", error);
    }
  });
}

// 订阅---start---
const onSubscribeSuccess = (e) => {
  let subscribeDetails = JSON.parse(e.detail.subscribeDetails); // 全部的模板
  for (let i in subscribeDetails) {
    let subKey = subscribeDetails[i]; // 获取每个模板的状态
    let status = JSON.parse(subKey);
    console.log("success:状态：", status.status);
    switch (status.status) {
      case "reject":
        Tips({ title: `用户拒绝订阅消息` });
        break;
      case "cancel":
        Tips({ title: `用户取消订阅消息` });
        break;
      case "filter":
        Tips(`第${i}条消息应该标题同名被后台过滤`);
        break;
      default:
        addTipHandler();
        // 允许
        break;
    }
  }
};

const onSubscribeError = (err) => {
  uni.showModal({
    title: err,
  });
  console.log("出现错误");
};
// ----订阅end------------

// 跳转公众号关注start-----
function goMpHanlder() {
  window.location.href =
    "https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzkzMjk1NjU4Mg==&scene=124#wechat_redirect";
}
// 跳转公众号关注end------
</script>

<style scoped lang="scss">
::v-deep .uni-table {
  min-width: auto !important;
  background: unset !important;
  .uni-table-scroll {
    overflow: visible;
  }
  // 改表头字体样式
  .uni-table-th {
    border: none;
    border-right: 1px solid var(--view-td-right);
    background: var(--view-th1-color);
    font-size: 24rpx;
    font-weight: normal;
    color: var(--view-th-font-color);
  }
  .table--border {
    border: none;
  }
  .uni-table-td {
    border: none;
    border-right: 1px solid var(--view-td-right);
    // padding-top: 10rpx;
    // padding-bottom: 10rpx;
    padding: 10rpx 0;
  }
  .uni-table-tr:nth-child(2n + 2),
  .uni-table-tr:nth-child(2n + 2):hover {
    background: var(--view-th2-color);
  }
  .uni-table-tr:nth-child(2n + 3),
  .uni-table-tr:nth-child(2n + 3):hover {
    background: var(--view-th3-color);
  }
}
.share_makser {
  position: fixed;
  z-index: 999;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.6);
  .img_box {
    position: absolute;
    right: 30rpx;
    top: 0;
    width: 370rpx;
    height: 470rpx;
    image {
      width: 100%;
      height: 100%;
    }
  }
}
.wrap {
  // max-width: 750rpx;
  margin: 0 auto;
  // padding-top: 300rpx;
  min-height: 100vh;
  background: var(--view-linear-home-bg);
  position: relative;
  .free_tip {
    text-align: center;
    color: var(--view-logoName-color);
    font-size: 28rpx;
    margin-top: 30rpx;
  }
  .pop_box {
    border-radius: 20rpx 20rpx 0 0;
    overflow: hidden;
    background: #fff;
    padding-bottom: 50rpx;
    .pop_title {
      height: 80rpx;
      line-height: 80rpx;
      color: #2e2e2e;
      font-size: 34rpx;
      font-weight: 700;
      text-align: center;
      border: 2rpx solid #f5f7f7;
      border-bottom: 2rpx solid #f5f7f7;
    }
    .pop_footer {
      margin-top: 200rpx;
      .pop_btn_item {
        font-weight: bold;
        margin: 0 auto;
        border-radius: 20rpx;
        text-align: center;
        overflow: hidden;
        width: 45%;
        padding: 10px 0;
        font-size: 13px;
        color: var(--view-fontColor);
        border: 2px solid var(--view-theme);
      }
      .btn_item2 {
        background: var(--view-theme);
        color: var(--view-fontColor);

        box-shadow: 0px 4px 20px 0px rgba(221, 203, 157, 0.4);
      }
    }
    .pop_body {
      padding: 30rpx 20rpx;
      .set_item {
        position: relative;
        border-radius: 11rpx;
        background: rgba(244, 246, 247, 1);
        padding: 30rpx 60rpx;
        margin-bottom: 20rpx;
        .iconfont {
          position: absolute;
          left: -10rpx;
          top: -10rpx;
          font-size: 40rpx;
        }
        .black {
          color: rgba(46, 44, 44, 1) !important;
        }
        .input_item {
          text-align: center;
          position: relative;
          width: 33.33%;
          color: rgba(125, 136, 140, 1);

          font-size: 28rpx;
          &:not(:first-child)::before {
            position: absolute;
            content: "";
            top: 50%;
            transform: translateY(-50%);
            left: 0;
            width: 2rpx;
            height: 110%;
            border-radius: 11rpx;
            background: rgba(219, 217, 217, 1);
          }
          .input_placeholder {
            color: rgba(125, 136, 140, 1);
          }
          input {
            text-align: center;
            color: rgba(46, 44, 44, 1);
            font-size: 28rpx;
          }
        }
      }
      .set_item1 {
        padding: 0 60rpx;
        font-weight: bold;
        background: unset;
        .input_item {
          &::before {
            display: none;
          }
        }
      }
    }
  }
  .pop_box2 {
    width: 560rpx;
    border-radius: 20rpx;
    overflow: hidden;
    background: #fff;
    padding: 30rpx;
    .pop_title {
      height: 80rpx;
      line-height: 80rpx;
      color: #2e2e2e;
      font-size: 34rpx;
      font-weight: 700;
      text-align: center;
      border: 2rpx solid #f5f7f7;
    }
    .info_box {
      margin-bottom: 20rpx;
      .address_info {
        text-align: center;
        color: #272636;
      }
    }
    .btn_box {
      width: 500rpx !important;
      border-radius: 99rpx;
    }
  }
  .pop_box1 {
    position: relative;

    // height: 625rpx;
    background: #fff;
    .iconfont {
      position: absolute;
      right: 15rpx;
      top: 15rpx;
      font-size: 40rpx;
      color: #c4c4c4;
    }
    .pop_title {
      height: 80rpx;
      line-height: 80rpx;
      color: #2e2e2e;
      font-size: 34rpx;
      font-weight: 700;
      text-align: center;
      border: 2rpx solid #f5f7f7;
    }
    .info_box {
      padding: 30rpx;

      .phone_box {
        .phone_item {
          margin-bottom: 30rpx;

          image {
            display: block;
            width: 74rpx;
            height: 74rpx;
            border-radius: 50%;
            margin-right: 20rpx;
          }
          .address_info {
            .text1 {
              font-size: 24rpx;
              margin-bottom: 10rpx;
            }
            .text2 {
              font-size: 28rpx;
            }
          }
        }
      }
    }
  }

  .footer {
    padding: 0 20rpx;
    // width: 680rpx;
    margin: 0 auto;
    margin-top: 50rpx;
    font-size: 30rpx;
    color: var(--view-tabale-title);
    .red_class {
      color: #e91414;
    }
    .text_item {
      margin-right: 50rpx;
      margin-bottom: 20rpx;
      .iconfont {
        font-size: 30rpx;
        margin-right: 10rpx;
      }
    }
  }
  .open_box {
    padding: 10rpx 20rpx;
    background: rgba(255, 255, 255, 0.2);
    margin-bottom: 30rpx;
    color: var(--view-tabale-title);
    .menu_item {
      color: #fff;
      font-size: 24rpx;
      background: rgba(0, 0, 0, 0.5);
      border-radius: 99rpx;
    }
    .status_box {
      border-radius: 6rpx;
      color: #fff;
      margin-left: 10rpx;
      font-size: 20rpx;
      background: #1d8c29;
    }
    .gray {
      background: #96999d;
    }
  }
  .notice_box {
    width: 100%;
    margin-bottom: 20rpx;
    color: var(--view-tabale-title);
  }
  .header {
    position: relative;
    width: 100%;
    margin-bottom: 20rpx;
    // height: 370rpx;
    height: auto;
    .top_box,
    .menu_box {
      position: absolute;

      z-index: 99;
      right: 10rpx;
      // transform: translateX(-50%);
      bottom: 10rpx;
      // width: 700rpx;
      border-radius: 16rpx;
      // box-shadow: 0px 4rpx 20rpx 0px rgba(220, 202, 156, 0.3);
      // background: var(--view-linear-home);
      .top_item {
        font-size: 24rpx;
        color: var(--view-fontColor);
        .iconfont {
          font-size: 24rpx;
          margin-right: 5rpx;
        }
      }
      .open_right {
        overflow: hidden;
        .top_time_box {
          text-align: center;
          color: var(--view-tabale-title);
          line-height: 40rpx;
          font-size: 26rpx;
        }
        .top_status_box {
          margin-top: 10rpx;
          font-size: 20rpx;
          color: var(--view-tabale-title);
          .status_box {
            color: #fff;
            border-top-left-radius: 10rpx;
            border-bottom-left-radius: 10rpx;
            background: #d43030;
            border: 1px solid var(--view-border-color);
            border-right: unset;
          }
          .close_status {
            background: #1d8c29;
          }
          .status_text {
            background: var(--view-status-bg);
            border-top-right-radius: 10rpx;
            border-bottom-right-radius: 10rpx;
            border: 1px solid var(--view-border-color);
            border-left: unset;
          }
        }
      }
    }
    .menu_item {
      color: #fff;
      font-size: 24rpx;
      margin-left: 20rpx;
      background: rgba(0, 0, 0, 0.5);
      border-radius: 99rpx;
    }
    .minHeight {
      min-height: 150rpx !important;
    }
    .swiper_box {
      position: relative;
      width: 100%;
      min-height: 100rpx;
      overflow: hidden;
      .masker {
        position: absolute;
        z-index: 10;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background: rgb(0, 0, 0);
        opacity: 0.05;
      }
      .swiper_item {
        width: 100%;
        height: 100%;
        image {
          width: 100%;
          height: 100%;
        }
      }
    }
    .logo_name {
      position: absolute;
      z-index: 20;
      left: 24rpx;
      top: 30rpx;
      font-size: 30rpx;

      .logo_box {
        width: 80rpx;
        height: 80rpx;
        border: 2rpx solid #fff;
        border-radius: 8rpx;

        overflow: hidden;
        image {
          width: 100%;
          height: 100%;
        }
      }
      text {
        font-size: 64rpx;
        color: var(--view-logoName-color);
        font-weight: 600;
        // margin-left: 10rpx;
      }
    }
    .extra_box {
      z-index: 20;
      position: absolute;
      right: 10rpx;
      top: 10rpx;
      .extra_item {
        color: #fff;
        font-size: 24rpx;
        margin-left: 20rpx;
        background: rgba(0, 0, 0, 0.5);
        border-radius: 99rpx;
        border: 2rpx solid #fff;
      }

      .share_box {
        width: 60rpx;
        height: 60rpx;
        color: #fff;
        padding: 10rpx 20rpx;
        border-radius: 50%;
        border: 2rpx solid #fff;
        background: rgba(0, 0, 0, 0.4);
        margin-left: 20rpx;
        .iconfont {
          color: #fff;
          font-size: 25rpx;
          font-weight: bold;
        }
      }
    }
  }

  .container {
    padding: 0 10rpx;
    position: relative;

    .table_box {
      // width: 720rpx;
      margin: 0 auto;
      border: 2px solid var(--view-tabale-border);
      border-radius: 16rpx;
      margin-bottom: 20rpx;
      // background: rgba(255, 255, 255, 0.45);
      overflow: hidden;
      font-family: "NotoSansSC";
      .table_th {
        font-size: 32rpx;
        font-weight: bold;
      }
      .table_td {
        // font-weight: 500;
        line-height: 50rpx;
        color: rgb(247, 0, 0);
        line-height: 70rpx;
        font-size: 38rpx;
      }
      .name_td {
        color: var(--view-tabale-title);

        font-weight: normal;
        white-space: nowrap;
      }

      .font_samll {
        line-height: 40rpx;
      }
    }
    .hidde_title {
      margin-bottom: 0;
      border: none;
      border-radius: unset;
      .th1 {
        background: var(--view-th3-color) !important;
      }
      .th2 {
        background: var(--view-th2-color) !important;
      }
      .name_td,
      .table_td {
        padding: 0;
        min-width: 180rpx;
      }
      ::v-deep .uni-table-td {
        padding: 10rpx 0;
      }
    }
    .tabale_item {
      &:first-child .hidde_title {
        border-radius: 16rpx 16rpx 0 0;
      }
      &:last-child .hidde_title {
        border-radius: 0 0 16rpx 16rpx;
      }
    }
    .tabale_title {
      color: var(--view-tabale-title);
      text-align: center;
      font-family: Source Han Serif CN;
      font-size: 34rpx;
      line-height: 43rpx;
      letter-spacing: 10rpx;
      text-align: center;
      margin-bottom: 20rpx;
      font-weight: bold;
    }
  }
}
.followCode {
  .mask {
    z-index: 10000;
  }

  .pictrue {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 500rpx;
    // height: 720rpx;
    padding: 0 0 80rpx;
    border-radius: 12px;
    left: 50%;
    top: 50%;
    margin-left: -250rpx;
    margin-top: -360rpx;
    background: #fff;
    position: fixed;
    z-index: 10001;
    background-size: cover;
    background-repeat: no-repeat;

    .img_box {
      margin-top: 88rpx;
      width: 300rpx;
      height: 300rpx;

      image {
        width: 100%;
        height: 100%;
      }
    }

    .follow_text {
      color: #999;
      font-size: 30rpx;
      margin-top: 30rpx;
      text-align: center;
    }
  }
}
</style>
